﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using CC98.Xaml.Helpers;

namespace CC98.Metro.Controls
{
    public class VariableSizedGridView : GridView
    {
        public ISizeProvider SizeProvider
        {
            get { return (ISizeProvider)GetValue(SizeProviderProperty); }
            set { SetValue(SizeProviderProperty, value); }
        }
        public static readonly DependencyProperty SizeProviderProperty =
            DependencyProperty.Register("SizeProvider", typeof(ISizeProvider), typeof(VariableSizedGridView), new PropertyMetadata(new DefaultSizeProvider()));

        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            // Set row and column
            if (this.SizeProvider != null)
            {
                var size = this.SizeProvider.GetSize(item);
                VariableSizedWrapGrid.SetRowSpan((UIElement)element, size.Row);
                VariableSizedWrapGrid.SetColumnSpan((UIElement)element, size.Column);
            }
        }
    }
}
